package cn.lanqiao.system.dao;

import cn.lanqiao.system.entity.User;
import cn.lanqiao.system.vo.QueryUserVo;
import cn.lanqiao.system.vo.UserVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends tk.mybatis.mapper.common.Mapper<User> {


    @Select("<script>select u.*,r.* from system_user u, system_role r, system_user_role ur where u.user_id = ur.user_id and r.role_id = ur.role_id " +
            "        <if test=\"userName != null and userName != ''\">" +
            "           and u.user_name like  CONCAT('%',#{userName},'%')" +
            "        </if>" +
            "        <if test=\"email != null and email != ''\">" +
            "           and u.email like  CONCAT('%',#{email},'%')" +
            "        </if>" +
            "</script>")
    List<UserVo> selectUserByPage(QueryUserVo queryUserVo);

    @Select("select * from system_user where user_name = #{userName}")
    User checkUser(User user);

    @Insert("insert into system_user (user_name, password, email, create_time) values (#{userName},#{password},#{email},#{createTime})")
    @Options(useGeneratedKeys = true,keyProperty = "userId")
    void insertUser(User user);
}
